﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PPIDesktopClient.Entities;
using PPIProxy;
using System.Data;
using PPIDesktopClient.General;
using PPIProxy;
using VMind.Global;
using PPIMobileInterface;
namespace PPIDesktopClient.Logic
{
    public static class LVendor
    {
        public static EVendor SelectData(Int32 VendorID)
        {
            ConfigReader _Reader = ConfigReader.GetInstance();
            DataRow _Datarow = WVendor.SelectData(VendorID,_Reader.GetConnectionString()).Tables[0].Rows[0];
            EVendor _Vendor = new EVendor();
            
            _Vendor.VendorId = ConvertHelper.ToInt32(_Datarow["VendorID"]);
            _Vendor.Name = ConvertHelper.Tostring(_Datarow["Name"]);
            _Vendor.Status = ConvertHelper.Tostring(_Datarow["Status"]);
            return _Vendor;
        }

        public static List<EVendor> SelectAllIdName()
        {
            ConfigReader _Reader = ConfigReader.GetInstance();
            DataSet ds = WVendor.SelectAllIdName(_Reader.GetConnectionString());
            List<EVendor> _vendorList = new List<EVendor>();
            EVendor _vendor;
            foreach (DataRow  dr in ds.Tables[0].Rows)
            {
                _vendor = new EVendor();
                _vendor.VendorId = ConvertHelper.ToInt32(dr["VendorId"]);
                _vendor.Name = ConvertHelper.Tostring(dr["Name"]);
                _vendorList.Add(_vendor);
            }
            return _vendorList;
        }

        #region Mobile

        public static void InsertVendors(string connectionString)
        {
            List<EVendor> _vendors = SelectAllIdName();
            StringBuilder _query = new StringBuilder();
            foreach (EVendor e in _vendors)
            {
                _query.AppendLine("insert into tb_Vendor values (" + e.VendorId + ",'" + e.Name + "')");
            }
            Utils.InsertVendors(connectionString, _query.ToString());
        }

        #endregion

    }
}
